package cn.fourhundredandeighteen.service.impl;

import cn.fourhundredandeighteen.dao.SubjectStudentDao;
import cn.fourhundredandeighteen.service.SubjectStudentService;
import cn.fourhundredandeighteen.utill.MysqlConnect;

import java.util.List;

/**
 * @description:
 * @author: liuyongqi
 * @time: 2020/12/17
 */
public class SubjectStudentServiceImpl  implements SubjectStudentService {
    @Override
    public List<Long> getSubjectToStudentList(Long subjectId) {
        SubjectStudentDao subjectStudentDao= MysqlConnect.into().getMapper(SubjectStudentDao.class);
        try {
            List<Long> longs = subjectStudentDao.selectSubjectToStudent(subjectId);
            MysqlConnect.destroy();
            return longs;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public List<Long> getStudentToSubjectList(Long studentId) {
        SubjectStudentDao subjectStudentDao= MysqlConnect.into().getMapper(SubjectStudentDao.class);
        try {
            List<Long> longs = subjectStudentDao.selectStudentToSubject(studentId);
            MysqlConnect.destroy();
            return longs;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int insertStudentAndSubjectList(Long subjectId, Long[] studentIds) {
        SubjectStudentDao studentDao=MysqlConnect.into().getMapper(SubjectStudentDao.class);
        int i = studentDao.insertStudentAndSubjectList(subjectId, studentIds);
        MysqlConnect.destroy();
        if (i>0)
            return i;
        else
            return 0;
    }
}
